package com.lawyer.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import com.lawyer.entity.MoneyFlows;

@RepositoryRestResource(exported = false)
public interface MoneyFlowsRepository extends PagingAndSortingRepository<MoneyFlows, Long>, JpaSpecificationExecutor<MoneyFlows> {
	Page<MoneyFlows> findByUserId(String userId,Pageable pageable);
	
	
	/**
	 * 当天收益
	 */
	@Query(value = "select sum(changeMoney) from MoneyFlows where to_days(createdDate) = to_days(now())")
	Object earningsCurrDay();
	/**
	 * 最近7天收益
	 */
	@Query(value = "select sum(change_money) from money_flows where date_sub(curdate(), interval 7 day) <= date(created_date)", nativeQuery = true)
	Object earnings7Day();
	/**
	 * 最近30天收益
	 */
	@Query(value = "select sum(change_money) from money_flows where date_sub(curdate(), interval 30 day) <= date(created_date)", nativeQuery = true)
	Object earnings30Day();
	
	
	/**
	 * 总用户量
	 */
	@Query(value = "select sum(change_money) from money_flows", nativeQuery = true)
	int totalEarningsCount();

}
